﻿import mx.controls.gridclasses.DataGridColumn;


/**
 * @des 初始化控件样式
 * @param ml 要初始化的DG控件
 */
function initMeetingList(ml:Object) {
	ml.headerHeight = 25;
}


/**
 * @des 创建DataGrid控件头
 * @param Id 列ID
 * @param w 列宽
 * @param ht 列名
 * @param dg DataGrid控件实例名
 */
function createDGHeader(Id:String, w:Number, ht:String, dg:Object) {
	var column:DataGridColumn;
	
	column = new DataGridColumn(Id);
	column.width = w;
	column.headerText = ht;
	dg.addColumn(column);
}


// 初始化控件
initMeetingList(meetingList);


// @des 创建DG控件列
createDGHeader("id", 40, "编号", meetingList);
createDGHeader("meetingMode", 70, "会议模式", meetingList);
createDGHeader("meetingName", 200, "会议名称", meetingList);
createDGHeader("meetingTheme", 210, "会议主题", meetingList);
createDGHeader("memberList", 250, "成员列表", meetingList);
createDGHeader("createUser", 100, "创建人", meetingList);
createDGHeader("createTime", 120, "创建时间", meetingList);

var meetingListSo:SharedObject = SharedObject.getRemote("meetingList", nc.uri,true);
meetingListSo.connect(nc);

// 同步服务器端会议列表共享变量
meetingListSo.onSync = function() {
	var meetingArray:Array = new Array();
	
	/**
	 * @des 将服务器端数据装载到数组中
	 *      mlo对象的声明一定要放在循环体内
	 */
	for (var i in meetingListSo.data) {
		if (chkMember(memberName, meetingListSo.data[i].memberList)) {
			var mlo:Object = new Object();
			mlo.id = meetingListSo.data[i].id;
			mlo.meetingMode = meetingListSo.data[i].meetingMode;
			mlo.meetingName = meetingListSo.data[i].meetingName;
			mlo.meetingTheme = meetingListSo.data[i].meetingTheme;
			mlo.memberList = getMemberName(meetingListSo.data[i].memberList);
			mlo.createUser = getMemberName(meetingListSo.data[i].createUser);
			mlo.createTime = getTime(meetingListSo.data[i].createTime);
			
			// 去掉后面多余的逗号
			mlo.createUser = mlo.createUser.substr(0, mlo.createUser.length - 1);
		
			meetingArray[meetingArray.length] = mlo;
		}
	}
	
	// 清除会议列表
	meetingList.removeAll();
	
	// 用新数据填充会议列表
	for (var i:Number = 0; i < meetingArray.length; i++) {
		meetingList.addItem(meetingArray[i]);
	}
};